<template>
    <!-- 对话框表单 -->
    <!-- 建议使用 Prettier 格式化代码 -->
    <!-- el-form 内可以混用 el-form-item、FormItem、ba-input 等输入组件 -->
    <el-dialog
        class="ba-operate-dialog"
        :close-on-click-modal="false"
        :model-value="['Add', 'Edit'].includes(baTable.form.operate!)"
        @close="baTable.toggleForm"
        width="50%"
        :style="{ height: '90vh',top:'-10vh !important'}"
    >
        <template #header>
            <div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
                订单操作
            </div>
        </template>
        <el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar" style="height:86vh">
            <div
                class="ba-operate-form"
                :class="'ba-' + baTable.form.operate + '-form'"
                :style="config.layout.shrink ? '':'width: calc(100% - ' + baTable.form.labelWidth! / 10 + 'px)'"
            >
                        <el-card style="max-width:100%;margin-left: 20px;">
                            <template #header>
                            <div class="card-header">
                                <b>订单发货</b>
                            </div>
                            </template>
                            <div>
                                
                                <FormItem label="快递公司" type="remoteSelect" v-model="baTable.form.items!.logistics_company" prop="logistics_company" :input-attr="{ pk: 'eid', field: 'name', 'remote-url': '/admin/order.Order/getExpress' }"/>

                                <el-form-item label="快递单号">
                                   <el-input v-model="baTable.form.items!.logistics_no" />
                                </el-form-item>

                                <el-form-item label="" v-if="baTable.form.items!.is_pay == 1">
                                    <el-button type="primary" @click="handleOrder('fahuo')">确定发货</el-button>
                                </el-form-item>

                            </div>
                            
                        </el-card>

                        <el-card style="max-width:100%;margin-left: 20px;margin-top: 20px;">
                            <template #header>
                            <div class="card-header">
                                <b>订单退款</b>
                            </div>
                            </template>
                            <div style="margin-bottom:15px;">
                                <el-form-item label="退款金额">
                                   <el-input v-model="baTable.form.items!.money" :disabled="baTable.form.items!.is_pay==1?false:true"/>
                                </el-form-item>
                                
                            </div>
                            <el-form-item label="" v-if="baTable.form.items!.is_pay==1 && baTable.form.items!.order_status != 8">
                                    <el-button type="primary" @click="handleOrder('tuikuan')">确定退款</el-button>
                            </el-form-item>
                            
                        </el-card>


                        <el-card style="max-width:100%;margin-left: 20px;margin-top: 20px;">
                            <template #header>
                            <div class="card-header">
                                <b>订单备注</b>
                            </div>
                            </template>
                            <div style="margin-bottom:15px;">
                                <el-input
                                        v-model="baTable.form.items!.orderdes"
                                        style="width:100%"
                                        :rows="2"
                                        type="textarea"
                                        placeholder="请输入"
                                />
                                
                            </div>
                            <el-form-item label="">
                                    <el-button type="primary" @click="handleOrder('beizhu')">修改备注</el-button>
                            </el-form-item>
                            
                        </el-card>
                        <el-card style="max-width:100%;margin-left: 20px;margin-top: 20px;">
                            <template #header>
                            <div class="card-header">
                                <b>修改金额</b>
                            </div>
                            </template>
                            <el-form-item label="订单金额">
                                   <el-input v-model="baTable.form.items!.money" :disabled="baTable.form.items!.is_pay==1?false:true"/>
                            </el-form-item>
                            <el-form-item label="" v-if="baTable.form.items!.is_pay == 0">
                                    <el-button type="primary" @click="handleOrder('change_price')">修改金额</el-button>
                            </el-form-item>
                        </el-card>

                        <el-card style="max-width:100%;margin-left: 20px;margin-top: 20px;margin-bottom: 50px;">
                            <template #header>
                            <div class="card-header">
                                <b>修改支付方式</b>
                            </div>
                            </template>
                            <div style="margin-bottom:15px">
                                <el-radio-group v-model="baTable.form.items!.pay_style">
                                    <el-radio :value="0">微信支付</el-radio>
                                    <el-radio :value="1">支付宝</el-radio>
                                    <el-radio :value="2">银行卡</el-radio>
                                    <el-radio :value="3">线下转账</el-radio>
                                </el-radio-group>
                            </div>
                            <el-form-item label="">
                                    <el-button type="primary" @click="handleOrder('change_ps')">修改支付方式</el-button>
                            </el-form-item>
                        </el-card>
            </div>
        </el-scrollbar>
     
    </el-dialog>
</template>

<script setup lang="ts">
import type { FormInstance, FormItemRule } from 'element-plus'
import { inject, reactive, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import FormItem from '/@/components/formItem/index.vue'
import { useConfig } from '/@/stores/config'
import type baTableClass from '/@/utils/baTable'
import { buildValidatorData } from '/@/utils/validate'
import { ElMessage,ElMessageBox} from 'element-plus'
import createAxios from '/@/utils/axios'
const config = useConfig()
const formRef = ref<FormInstance>()
const baTable = inject('baTable') as baTableClass

const { t } = useI18n()

const handleOrder = (type = '') => {
       ElMessageBox.confirm(
            '确定执行该操作吗?',
            '系统提示',
            {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
            }
        )
        .then(() => {
            return createAxios(
                        {
                            url: '/admin/order.Order/handleOrder',
                            method: 'post',
                            data: { type: type , 'data':baTable.form.items}
                        }
                    ).then(res => {
                            if(res.data.code == 100){
                                ElMessage({'message':res.data.msg,'type':'error'})

                            }else{
                                ElMessage({'message':"保存成功",'type':'success'})

                                baTable.getIndex()?.then(() => {
                                    baTable.initSort()
                                    baTable.dragSort()
                                })
                                
                            }

                    })
        })
        .catch(() => {

        })



}
</script>

<style scoped lang="scss"></style>
